//                              _ooOoo_
//                             o8888888o
//                             88" . "88
//                             (| -_- |)
//                              O\ = /O
//                           ____/`---'\____
//                        .   ' \\| |// `.
//                         / \\||| : |||// \
//                        / _||||| -:- |||||- \
//                         | | \\\ - /// | |
//                       | \_| ''\---/'' | |
//                        \ .-\__ `-` ___/-. /
//                    ___`. .' /--.--\ `. . __
//                  ."" '< `.___\_<|>_/___.' >'"".
//                 | | : `- \`.;`\ _ /`;.`/ - ` : | |
//                    \ \ `-. \_ __\ /__ _/ .-` / /
//           ======`-.____`-.___\_____/___.-`____.-'======
//                              `=---='
//                   高山仰止,景行行止.虽不能至,心向往之。
//           .............................................

import React, {memo, useState} from 'react';
import {renderRoutes} from 'react-router-config';
import {HashRouter} from 'react-router-dom';
import {Provider} from 'react-redux';
import {PersistGate} from 'redux-persist/lib/integration/react';
import {Spin} from "antd";

import routes from './router';
import store from "./store";
import {persistor} from "./store";

export default memo(function App() {
  const [loading, setLoading] = useState(store.getState().loadingReducer.isLoading);
  store.subscribe(() => setLoading(store.getState().loadingReducer.isLoading));
  return (
    // Provider可以解决数据层层传递和每个组件都要传props的问题
    //https://blog.csdn.net/yexudengzhidao/article/details/103509507?ops_request_misc=&request_id=&biz_id=102&utm_term=react%20Provider%E7%BB%84%E4%BB%B6&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-103509507.nonecase&spm=1018.2226.3001.4187
    <Provider store={store}>
      <HashRouter>
        <PersistGate persistor={persistor}>
          {renderRoutes(routes)}
          <Spin size="large" className={"loading " + (loading ? "isLoading" : "")} tip="Loading..."/>
        </PersistGate>
      </HashRouter>
    </Provider>
  );
});


